import {mapActions, mapState} from "vuex"
import {debounce} from "../../js/common.js"
export default {
  data () {
    return {
      msg: '',
      sw: true,
      keywords: "",
      searchList: [],
      rList: [],
      nCount: 0,
    }
  },
  watch: {
    keywords(v){
      debounce(() => {
        if (v.trim() === "") {
          this.searchList = [];
        } else {
          this.searchList = this.rList.filter((i) => {
            return i.c.includes(v) || i.p.includes(v) || i.h.includes(v);
          });
        }
      }, 100);
    }
  },
  methods: {
    ...mapActions([
      '_title'
    ]),
    scrollInit(){

    },
    refresh(done){
      setTimeout(() => {
        done();
        window.vToast("刷新成功");
      }, 600);
    },
    loadMore(done){
      this.nCount++;
      setTimeout(() => {
        done(true)
      }, 200);
    },
    getTitle(v){
      let s = "";
      switch (parseInt(v)) {
        case 1:
          s = "收件箱";
          break;
        case 2:
          s = "发件箱";
          break;
        case 3:
          s = "草稿箱";
          break;
      }
      this._title(s);
    },
    checkList(v){
      let f = this.$route.params.flag;
      if (parseInt(f) === 3) {
        this.$router.push({path: `/editPage?flag=3&id=${v.id}`});
      } else {
        this.$router.push({name: "inboxDetail", params: {id: v.id}});
      }
    },
    getList(v){
      if (parseInt(v) === 3) {
        this.rList = this.draftsList;
      } else {
        this.rList = this.receivedList;
      }
    },
    init(){
      let f = this.$route.params.flag;
      this.getList(f);
      this.getTitle(f);
    }
  },
  components: {},
  computed: {
    ...mapState([
      'receivedList',
      'draftsList',
    ]),
  },
  activated() {
    this.init();
  },
}
